package utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;

public class Utils {
    public static void printList(List<String> list){
        String result = list.stream().collect(Collectors.joining(","));
        System.out.println(result);
    }

    public static void printListList(List<List<String>> list){
        for (List<String> sublist : list) {
            String result = sublist.stream().collect(Collectors.joining(","));
            System.out.println(result);
        }
    }

    public static void printInt(int a){
        System.out.println(a);
    }

    public static void printIntArr(int[] a){
                String result = Arrays.stream(a)
                .mapToObj(String::valueOf)
                .collect(Collectors.joining(","));
        System.out.println(result);
    }

    public static void printIntArrArr(int[][] a){
        StringJoiner join = new StringJoiner(";");
        for(int[] arr : a){
            String result = Arrays.stream(arr)
                    .mapToObj(String::valueOf)
                    .collect(Collectors.joining(","));
            join.add(result);
        }
        System.out.println(join.toString());
    }

    public static void printIntList(List<Integer> a){
        String result = a.stream()
                .map(String::valueOf)
                .collect(Collectors.joining(","));
        System.out.println(result);
    }

    public static void printIntListList(List<List<Integer>> a){
        for(List<Integer> list : a){
            printIntList(list);
        }
    }

    public static void printLinkList(ListNode res){
        StringJoiner join = new StringJoiner(",");
        while (res != null){
            join.add(String.valueOf(res.val));
            res = res.next;
        }
        System.out.println(join.toString());
    }


}
